Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
"TypeError: $ is not a function" when trying to use cheerio like jquery

I am trying to make a bot to check if an item is in stock. I based it off of this video https://www.youtube.com/watch?v=57TEZq8O360, but changed the url. Although I can console.log the content of the webpage when I try to use cheerio like jquery I get this error "TypeError: $ is not a function". I know cheerio is installed and works as I have declared it with "const $ = require('cheerio');" and have been able to use it elsewhere in my file. Is there a typo that I am missing? My broken code is below.

async function checkStock(page){
await page.reload();
let content = await page.evaluate(() => document.body.innerHTML);
console.log(content);
$("link[itemprop='availability']", content).each(function(){ //error here
    let instock= $(this).attr('href').toLowerCase().includes("outofstock");
     if(instock){
        console.log("no"); 
  }
});}



    
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to load the HTML into cheerio, and then cheerio will give you the $ API:

const $ = require("cheerio");

// ...

async function checkStock(page){
    await page.reload();
    const content = await page.evaluate(() => document.body.innerHTML);
    const $ = cheerio.load(content);

    $("link[itemprop='availability']", content).each(function(){ //error here
        let instock = $(this).attr('href').toLowerCase().includes("outofstock");
        if (instock) {
            console.log("no"); 
        }
    });
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda